package com.tyun.modules.sys.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tyun.common.aspect.BaseLog;
import com.tyun.common.utils.R;
import com.tyun.modules.sys.entity.SysMenu;
import com.tyun.modules.sys.entity.SysRole;
import com.tyun.modules.sys.service.ISysRoleService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统角色
 *
 * @author congcong tao
 * @date 2018/5/14 16:14
 */
@RestController
@RequestMapping("sysRole")
public class SysRoleController extends CommonController{

    private static final Logger logger = LogManager.getLogger(SysRoleController.class);

    @Autowired
    private ISysRoleService sysRoleService;

    @BaseLog("查询所有角色")
    @GetMapping("/list")
    public List<SysRole> list(SysRole sysRole){
        EntityWrapper<SysRole> ew = new EntityWrapper<>(sysRole);
        List<SysRole> sysRoleList = sysRoleService.selectList(ew);
        return sysRoleList;
    }
    
    @GetMapping("/page")
    public R page(Page<SysRole> page, SysRole sysRole){
        sysRoleService.selectPage(page, new EntityWrapper<>(sysRole));
        return R.ok().put("rows", page.getRecords()).put("total", page.getTotal());
    }

    /**
     * 菜单信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable String id){
        SysRole role = sysRoleService.selectById(id);
        return R.ok().put("role", role);
    }
}
